<?php 
require_once('database.php');
$link=connectDB();
$tbl_name='topic'; // Table name

$content=$_POST['txtDefaultHtmlArea'];
$describle=$_POST['describle'];

$checkuploadimage = 0;
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_POST['title'] != "")
|| ($_POST["category"] != "")
|| ($_POST["describle"] != "")
|| ($_POST["txtDefaultHtmlArea"] != "")
|| ($_POST["type"] != "")))
  {
  if ($_FILES["file"]["error"] > 0)
    {
   	 $checkuploadimage = 0;
    }
  else
    {
    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
	     $checkuploadimage = 0;
      }
    else
      {
      	$checkuploadimage = 1;
		move_uploaded_file($_FILES["file"]["tmp_name"],
		  "upload/" . $_FILES["file"]["name"]);
      }
    }
  }
else
  {
  $checkuploadimage = 0;
  }

if($checkuploadimage == 1) {
	$imagetitle = "admin/upload/" . $_FILES["file"]["name"];
	$text = $_POST['title'];
	if($text == "") {
		header('Location: newtopic.php');
	}else {
		if($_POST["category"] == "") {
			header('Location: newtopic.php');
		}else {
			$type = $_POST["category"];

			$sql="INSERT INTO $tbl_name(titleimage, titletext, subdescrible , content, category ) VALUES ('$imagetitle', '$text', '$describle', '$content', '$type');";
			$result=mysql_query($sql, $link);
			header('Location: main.php');
		}
	}
}else {
	header('Location: newtopic.php');
}
?>